package com.cloud.yangfeiself.dto;

import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.http.HttpStatus;

import java.io.Serializable;

/**
 * 响应结果包装类
 *
 * @author Yang Fei
 * @date 2021/2/22
 */
@Data
@NoArgsConstructor
public class ResResult implements Serializable {

    private Integer code;

    private String msg;

    private Object data;

    public ResResult(Integer code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static ResResult ok() {
        return new ResResult(HttpStatus.OK.value(), HttpStatus.OK.getReasonPhrase(), null);
    }

    public static ResResult ok(Object data) {
        return new ResResult(HttpStatus.OK.value(), HttpStatus.OK.getReasonPhrase(), data);
    }

    public static ResResult error() {
        return new ResResult(HttpStatus.INTERNAL_SERVER_ERROR.value(),
                HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase(), null);
    }

    public static ResResult error(Integer code, String msg) {
        return new ResResult(code,msg, null);
    }

}
